<template>
    <Modal @on-ok="cancels" @on-cancel="cancels"
        v-model="insuranceModalVisible"
        :title="modalTitle"
        :width="1200"
        :closable="false"
        :mask-closable="false"
    >
        <rui-page :defines="defines">
            <rui-form inline :label-width="180" :form-options="searchFormOptions" :read-only="false"
                      ref="searchForm"></rui-form>
            <Row style="text-align: center;">
                <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                <Button @click="handleReset" icon="md-refresh">重置</Button>
            </Row>
            <rui-table v-if="!this.Obj.roleType"
                       :defineId="'insurancePopUpsDefine'"
                       :fixedLeft="['action']"
                       :showIndex="false"
                       :select="false"
                       :columns="insuranceManageColumns"
                       @loadDatas="queryData"
                       @on-row-dblclick="handleRowChange"
                       ref="insurancePopTable"
            >
            </rui-table>
            <rui-table v-if="this.Obj.roleType"
                       :defineId="'insurancePopUpsDefine'"
                       :fixedLeft="['action']"
                       :showIndex="false"
                       :select="false"
                       :columns="insuranceManageColumn"
                       @loadDatas="queryData"
                       @on-row-dblclick="handleRowChange"
                       ref="insurancePopTable"
            >
            </rui-table>
        </rui-page>
    </Modal>
</template>
<script>
    import insurancePopUpsDefine from "./define/insurance-popups-define";
    import {
        getInsurancePopList,
    } from "_p/basic/api/contract/common/cust-insurance/cust-insurance";
    import {channelType} from "_p/basic/api/contract/channel-type/channel-type";

    export default {
        props: {
            Obj: {
                type: Object
            }
        },
        data() {
            return {
                insuranceModalVisible: true,
                modalTitle: "已激活案件",
                searchFormOptions: [
                    {
                        grids: [
                            {
                                defineId: "insurancePopUpsDefine",
                                span:7,
                                fields: ["applyNo", "custName"]
                            },
                            {
                                defineId: "insurancePopUpsDefine",
                                span:7,
                                fields: ["certNo", "phone"]
                            },
                            {
                                defineId: "insurancePopUpsDefine",
                                span:7,
                                fields: ["contractNo"]
                            }
                        ]
                    }
                ],
                insuranceManageColumns: [
                    'applyNo', 'custName', 'contractNo', 'certNo', 'phone', 'contractStatus', 'custRole', 'channelType'],
                insuranceManageColumn: ['applyNo', 'custName', 'certNo', 'phone', 'custRole']
            };
        },
        computed: {
            defines() {
                return [
                    {
                        id: "insurancePopUpsDefine",
                        fields: insurancePopUpsDefine
                    }
                ];
            }
        },
        mounted() {
            this.getListData();
            this.insuranceModalVisible = true;
            if (this.Obj.roleType) {
                this.$refs.searchForm.setFiledHide("contractNo", true);
            }
        },
        methods: {
            getListData(pageNumber = 1, pageSize = 10) {
                this.$refs.searchForm.setFiledValue("pageNumber", pageNumber);
                this.$refs.searchForm.setFiledValue("pageSize", pageSize);
                getInsurancePopList(this.$refs.searchForm.formData,channelType(this.$route.meta.params)).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.insurancePopTable.updateTableData(records, total);
                    }
                });
            },
            queryData(pageNumber, pageSize) {
                this.getListData(pageNumber, pageSize);
            },
            handleSearch() {
                this.getListData();
            },
            handleReset() {
                this.$refs.searchForm.resetFrom();
                // 重新加载数据
                this.getListData();
            },
            handleRowChange(row) {
                this.$emit("next", {contractNo: row.contractNo});
            },
            cancels() {
                this.$emit("cancel");
            }
        }
    };
</script>
